package com.letu.core.utils;

public class ExhIdUtils {
    private static String[] ArrDict = {"F", "A", "I", "R", "1", "6", "Z", "H", "a", "N"};
    private static String mKey = "E4ghj*Ghg7!rNIfb87hiknbolb$er57HBh";

    public static Boolean CheckKey(String strKey) {
        if (strKey == mKey) {
            return true;
        }

        return false;
    }

    public static String NumberEncode(long iSource) {
        long lRet = iSource * 1376 + 8137;
        String sTmp = lRet + "";
        String strRet = "";
        for (int i = 0; i < sTmp.length(); i++) {
            strRet = strRet + ArrDict[Integer.parseInt(sTmp.substring(i, i + 1))];
        }
        return strRet;
    }

    public static long NumberDecode(String strSource) {
        String sTmp = "";
        int j = 0;
        for (int i = 0; i < strSource.length(); i++) {
            for (j = 0; j < ArrDict.length; j++) {
                if (ArrDict[j] == strSource.substring(i, 1)) {
                    sTmp = sTmp + j;
                    break;
                }
            }
            //存在不合法字符，返回0
            if (j == ArrDict.length) {
                return 0;
            }
        }
        long lSource = Integer.parseInt(sTmp) - 8137;
        //不合法的数字
        if (lSource < 1) {
            return 0;
        }
        //不全法的数字，返回0
        if (lSource % 1376 != 0) {
            return 0;
        }
        long lRet = lSource / 1376;
        return lRet;
    }

    public static void main(String[] args) {
        String s = NumberEncode(737);
        System.out.println(s);
    }
}
